#include "stdafx.h"
#include "qlist.h"

using namespace micro::gui;

QList::QList(void)
{
}

QList::~QList(void)
{
}
bool QList::Create(QWindow *parent, int id)
{
	//LBN_SELCHANGE   
	CreateBaseWindow(GetWndClassName() ,nullptr,
			WS_CHILD
			|WS_VISIBLE
			|WS_BORDER 
			|LBS_NOINTEGRALHEIGHT 
			|WS_VSCROLL 
			|LBS_NOTIFY 

			,QRect(0,0,0,0),
				parent , id);
	//nu trebuie this, clasa inregistrata automat cu wndProc proprie
	//deci doar parintele primeste WM_NOTIFY



	return _window != nullptr;
}

int QList::AddString(const QString str)
{
	//assert(::IsWindow(_window));
	return (int)::SendMessage(_window, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)str);
}
QString QList::GetItemText(int nIndex )
{
	//assert(::IsWindow(m_window));

	QString sir;
	int len = (int)::SendMessage(_window, LB_GETTEXTLEN, nIndex, 0); 
		//se aloca len+1
	::SendMessage(_window, LB_GETTEXT, nIndex, (LPARAM)(LPCTSTR) sir.GetBuffer(len));
	//sir.ReleaseBuffer();
	return sir;
}
DWORD_PTR QList::GetItemData(int nIndex) const
{
	//assert(::IsWindow(_window));
	return ::SendMessage(_window, LB_GETITEMDATA, nIndex, 0); 
}

int QList::SetItemData(int nIndex, DWORD_PTR dwItemData)
{
	//assert(::IsWindow(m_window));
	return (int)::SendMessage(_window, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData); 
}





int QList::InsertString(int nIndex, QString str)
{
	//assert(::IsWindow(_window));
	return (int)::SendMessage(_window, LB_INSERTSTRING, nIndex, (LPARAM)(LPCTSTR)str); 
}

int QList::GetCurentSelected()
{
	//assert(::IsWindow(_window));
	return (int)::SendMessage(_window, LB_GETCURSEL, 0, 0);

}
void  QList::SetCurentSelected(int id )
{
	//assert(::IsWindow(_window));
	::SendMessage(_window, LB_SETCURSEL, id, 0);

}
void  QList::DeleteAll( )
{
	::SendMessage(_window, LB_RESETCONTENT, 0, 0);
}
 


void QList::EnsureVisible(int nItem, bool bPartialOK)
{ 
	//assert(::IsWindow(_window));
	::SendMessage(_window, LVM_ENSUREVISIBLE, nItem, MAKELPARAM((BOOL)bPartialOK, 0)); 
}

